#include<bits/stdc++.h>
using namespace std;
#define S_IT set<Node>::iterator	//S_IT = set_iterator
typedef bool type;

struct Node {
	unsigned int l;
	unsigned int r;
	mutable type data;
	Node(unsigned int a, unsigned int b = 0, type c = 0);
	bool operator <(const Node &a) const {
		return l < a.l;
	}
};

Node::Node(unsigned int a, unsigned int b, type c) {
	l = a;
	r = b;
	data = c;
}

set<Node> s;

S_IT split(unsigned int pos) {
	S_IT it = s.lower_bound(Node(pos));
	if (it != s.end() && it->l == pos)
		return it;
	--it;
	unsigned int l = it->l, r = it->r;
	type data = it->data;
	s.erase(it);
	s.insert(Node(l, pos - 1, data));
	return s.insert(Node(pos, r, data)).first;
}

void assign(unsigned int l, unsigned int r, type val) {
	S_IT it2 = split(r + 1), it1 = split(l);
	s.erase(it1, it2);
	s.insert(Node(l, r, val));
	return;
}

signed main() {
	int l, m;
	cin >> l >> m;

	for (int i = 0; i <= l; ++i) {
		static type temp = 0;
		s.insert(Node(i, i, temp));
	}
//	s.insert(Node(n, n, 0));

	while (m--) {
		int a, b;
		cin >> a >> b;
		assign(a, b, 1);
	}

	int ans = 0;
	S_IT it2 = split(l + 1), it1 = split(0);
	for (; it1 != it2; ++it1) {
		if (it1->data == 0)
			ans++;
	}
	cout << ans;
	return 0;
}
